

import 'package:flutter/material.dart';

class StatefulWidgetDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    throw UnimplementedError();
  }

}

class MyState extends StatefulWidget {
  const MyState({super.key});

  @override
  State<MyState> createState() => _MyState();

}

class _MyState extends State<MyState> {

  int _num = 0;

  void _increment() {
    setState(() {
      if (_num == 10) return;
      _num++;
    });
  }

  void _decrement() {
    setState(() {
      if (_num == 0) return;
      _num--;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Center(
        child: Column(
          children: [
            Padding(padding: const EdgeInsets.all(10), child: Text('$_num'),),
            ElevatedButton(onPressed: _increment, child: const Icon(Icons.add)),
            ElevatedButton(onPressed: _decrement, child: const Icon(Icons.exposure_minus_1))
          ],
        ),
      ),
    );
  }

}